﻿package
{
	import flash.display.Sprite;  
	import flash.display.MovieClip;  
	import flash.net.URLLoader;  
	import flash.net.URLRequest;  
	import flash.display.Loader;  
	import flash.events.Event;  
	import flash.filters.BitmapFilter;  
	import flash.filters.DropShadowFilter;  
	import flash.text.TextFormat;  
	import flash.text.TextField;  
	import flash.text.AntiAliasType;  
	import flash.events.MouseEvent;  
	import fl.transitions.Tween;  
	import fl.transitions.easing.*; 
	import fl.transitions.TweenEvent;  
	import flash.display.MovieClip
	import fl.containers.ScrollPane;
	import fl.containers.BaseScrollPane;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.net.*;
	
	public class ImageViewer extends MovieClip
	{
		var imageSrc:String;
		var imageDis:String;		
		
		var discriptiontext:TextField = new TextField();
		var screen:Sprite;
		var urlLoader:URLLoader;
		var imageBitmap:Bitmap;	
		
		var viewerStyle:int;
		// 1 = top centered with text below
		
		public function ImageViewer(s:String, d:String="", v:int=1 ): void
		{
			imageSrc = s;
			imageDis = d;
			viewerStyle = v;			
				
			screen = new Sprite();
			screen.graphics.beginFill(0xFFFFFF, 1);
			screen.graphics.drawRect(0,0,800,500);
			screen.graphics.endFill();
			addChild(screen);
			
			//discriptiontext.autoSize = "on";
			discriptiontext.text = imageDis;
			discriptiontext.textColor = 0x999999;
			discriptiontext.selectable = false;
			addChild(discriptiontext);
			
			imageLoad(imageSrc);
		}
		public function imageLoad(s:String):void
		{
			var loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
				
			var myrequest = new URLRequest(s);
			loader.load(myrequest);
		}
		public function imageLoaded(e:Event):void
		{
			var templateBitmap:Bitmap = e.target.content;
   			var templateBitmapData:BitmapData = templateBitmap.bitmapData;
			var imageBitmap:Bitmap = new Bitmap(templateBitmapData);
			addChild(imageBitmap);
			
			if (viewerStyle == 1) 
			{				
				imageBitmap.x = (this.width - imageBitmap.width)/2;
				imageBitmap.y = 10;
				
				discriptiontext.x = 200;
				discriptiontext.y = 200;
				
				trace(discriptiontext.text);				
			}
		}
			
	}
	
}